/*
 * CN_STATUS.cpp
 *
 *  Created on: 2013. 5. 21.
 *      Author: the2
 */


#include "../../User.h"
#include "CN_STATUS.h"

#include "../../NLogic/Space.h"
#include "../../NLogic/Monster.h"
#include "../../NLogic/Status.h"

namespace ProjectZ { namespace NCommand { namespace NBattle {

void CN_STATUS::OnExecute(User * pUser, ::Network::Packet * pPacket)
{
	/*
	 * CN_STATUS                             0x0506
	{
			   u8       u8status_type;              /// 상태이상타입
			   s16       s16total_frame;              /// 상태이상 유지시간
			   s16       s16per_frame;               ///        상태이상 발동 주기
			   s16       s16value;                     ///        상태이상 값
			   s8        s8value_type;                ///        상태이상 값타입( 0 : + , 1 : %)
			   s8        s8effect_action;              ///        상태이상 이펙트 ID
			   u32 u32defender_gid;                 ///        DEFENDER GID
			   u8        u8sender_type;              /// 몬스터여부 (0 : 주인공 1: 몬스터 2: 주인공소환, 3: 몬스터 소환)
			   s16 s16range;                         /// 상태영역
	}

	SN_STATUS                             0x0507
	{
			   u8       u8status_type;              /// 상태이상타입
			   s16       s16total_frame;              /// 상태이상 유지시간
			   s16       s16per_frame;               /// 상태이상 발동 주기
			   s16       s16value;                     /// 상태이상 값
			   s8        s8value_type;                /// 상태이상 값타입( 0 : + , 1 : %)
			   s8        s8effect_action;              /// 상태이상 이펙트 ID
			   u32 u32defender_gid;                 /// DEFENDER GID
			   u8        u8sender_type;              /// 몬스터여부 (0 : 주인공 1: 몬스터 2: 주인공소환, 3: 몬스터 소환)
			   s16 s16range;                         /// 상태영역
	}


	 *
	 *
	 */

	NLogic::Space * pSpace = pUser->GetSpace();
	if (NULL == pSpace)
	{
		DEBUGLOG("CN_STATUS NULL == pSpace");
		return;
	}

	NLogic::Status * pStatus = pUser->GetStatus();
	if (NULL == pStatus)
	{
		DEBUGLOG("CN_STATUS NULL == pStatus");
		return;
	}

	PREPARE_PACKET;

	uint8_t stype = 0;
	uint16_t stime = 0;
	uint16_t sinterval = 0;
	uint16_t svalue = 0;
	uint8_t svalue_type = 0;
	uint8_t seffect_id = 0;
	uint32_t defender_gid = 0;
	uint8_t ismonster = 0;
	int16_t s16range = 0;

	* pPacket >> stype >> stime >> sinterval >> svalue
		>> svalue_type >> seffect_id >> defender_gid >> ismonster >> s16range;


	if (stype == static_cast<uint8_t>(NLogic::Status::StatusType::BATTLEPET_REBIRTH))
	{
		NLogic::Status::Data * pData = pStatus->GetStausData(static_cast<NLogic::Status::StatusType>(stype));
		if (NULL == pData)
		{
			DEBUGLOG("CN_STATUS NULL == pData");
			return;
		}

		DEBUGLOG("BATTLEPET_REBIRTH CN_STATUS BATTLEPET_REBIRTH CALL GID : %d", pUser->GetUserSeq());

		pData->_bRegist = true;
		pData->_durationTime = stime;
		pData->_elapseTime = sinterval;
		pData->_value = svalue;
		pData->_valueType = svalue_type;
		pData->_effectID = seffect_id;
		pData->_defenderID = defender_gid;
		pData->_defenderType = ismonster;
	}

	::Network::Packet * pNoti = ::Network::GETPACKETPOOL()->SEND_NEW();
	* pNoti << stype << stime << sinterval << svalue
				<< svalue_type << seffect_id << defender_gid << ismonster << s16range;
	pNoti->MakePacket(CMD_SN_STATUS);
	pSpace->SendAllExceptMe(pNoti, pUser);
}

} /*NBattle*/ } /*NCommand*/ } /*ProjectZ*/
